feat: Propagate exceptions to AfterToolCallEvent for decorated tools (#1565)#1566
Open
charles-dyfis-net wants to merge 17 commits intostrands-agents:mainfrom
Open
feat: Propagate exceptions to AfterToolCallEvent for decorated tools (#1565)#1566charles-dyfis-net wants to merge 17 commits intostrands-agents:mainfrom
charles-dyfis-net wants to merge 17 commits intostrands-agents:mainfrom
Conversation
zastrowm
requested changes
Jan 28, 2026
Member
zastrowm
left a comment
There was a problem hiding this comment.
Good implementation! Left some comments/requested-changes of the tests
Member
|
Looks like there are also some linting failures; |
Member
Yeah thats my bad, I optimistically tried to resolve conflicts in the UI. Should be good now |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
About the unit test assertion changes suggested -- ...though when it's the exact same object being returned we can use |
9b3609b to
87977ef
Compare
zastrowm
previously approved these changes
Jan 28, 2026
zastrowm
reviewed
Jan 28, 2026
dbschmigelski
previously approved these changes
Jan 29, 2026
Co-authored-by: Arron Bailiss <arron@amazon.com>
…arams (strands-agents#1584) Co-authored-by: Dean Schmigelski <dbschmigelski+github@gmail.com>
mkmeral
previously approved these changes
Feb 3, 2026
pgrayy
previously approved these changes
Feb 3, 2026
mkmeral
approved these changes
Feb 4, 2026
pgrayy
approved these changes
Feb 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Motivation
Hook providers need the ability to distinguish between expected errors (like validation failures that the model should adjust for and retry) and unexpected errors (like assertion failures or configuration errors that should fail the task immediately). Currently,
AfterToolCallEvent.exceptionis alwaysNonefor@tool-decorated functions because the decorator catches all exceptions and converts them to error results before the executor can see them. This forces all tool errors to be returned to the model, even when propagating the exception would be more appropriate.Resolves: #1565
Public API Changes
ToolResultEventnow accepts an optionalexceptionparameter, andAfterToolCallEvent.exceptionis populated for decorated tools:The error result is still returned to the model by default; hooks must explicitly re-raise if they want to propagate.
Use Cases
AssertionError,ConfigurationError, etc. instead of letting the model retry futilelyValueErrorto return to the model while propagating other exceptionsRelated Issues
#1565
Documentation PR
strands-agents/docs#482
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.